//
//  HomeDataView.m
//  Feel_at_home
//
//  Created by dllo on 15/9/28.
//  Copyright © 2015年 Feel_at_home. All rights reserved.
//

#import "HomeDataView.h"

@implementation HomeDataView
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.cover_image_url = [[UIImageView alloc]init];
        [self addSubview:self.cover_image_url];
        
        self.title = [[UILabel alloc]init];
        [self addSubview:self.title];
        
        self.share_msg = [[UILabel alloc]init];
        [self addSubview:self.share_msg];
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat w = self.frame.size.width;
    CGFloat h = self.frame.size.height;
    
    self.cover_image_url.frame = CGRectMake(0, 0, w, h*0.35);
    
//    self.title.frame = CGRectMake(20, h*0.32, w - 20, h*0.2);
    CGFloat height = [self heightWithText:self.title.text];
    //使用中间变量赋值
    CGRect frame = self.title.frame;
    frame.size.height = height;
    self.title.frame = frame;

    [self.title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];
    [self.title setFont:[UIFont fontWithName:@"Helvetica-BoldOblique" size:21]];
//    self.title.textAlignment = 1;
    self.title.numberOfLines = 0;
    
    self.share_msg.frame = CGRectMake(5, h*0.45, w - 5, h*0.5);
    self.share_msg.font = [UIFont systemFontOfSize:18];
  
    self.share_msg.numberOfLines = 0;
   
}

- (CGFloat)heightWithText:(NSString *)content
{
    CGSize size = CGSizeMake(WIDTH - 30, 10000);
    //字体大小一定与显示内容的label字体大小一致
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0] forKey:NSFontAttributeName];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
